package com.xiaojianhx.demo.algorithm.sort;

/**
 * 05 插入排序
 *
 * @author xiaojianhx
 * @version V1.0.0 $ 2021-07-07 09:52:46 init ---- xiaojianhx
 */
public class Algorithm_Sort_05_InsertionSort {

    public static void sort(int[] arr) {

        var l = arr.length;
        var p = 0;
        var c = 0;

        for (var i = 1; i < l; i++) {

            p = i - 1;
            c = arr[i];

            while (p >= 0 && arr[p] > c) {
                arr[p + 1] = arr[p];
                p--;
            }

            arr[p + 1] = c;
        }
    }
}
